<?php 
/**   
   Modelos de contacto entrega -- pertenece a modelo de entrega
   @author Natanael  
*/ 

class contactoentregam extends Model{
	
	  private $_nameTable = "EN_contactosEntrega ";
	  
	  public function __construct()
	  {
	  	   parent::Model();
		   $this->load->database();  	   
	  }
	  
	  public function loadDataContactoEntrega($start = false, $offset = false, $sortname = false, $sortorder = false) {
			
			if($offset != false)
				$this->db->limit($offset, $start);
	  	
	  	  $result = $this->db->get_where($this->_nameTable);
	  	  return $this->getModeloArrayFromQueryResult($result);
	  	
	  }
	  
	 /**
	 * Script Cambial tipo de servicio y clasificacion de servicio
	 */

    public function generarScript($idServicioWhere, $clasificacion, $idServicio = false)
	{
		
		$companias = $this->mcompania->loadCompaniasWhere(array("IdServicio" => $idServicioWhere));
		
		foreach($companias as $compania){
			
			   $idInbound = $compania->getIdCompania();
			   
			   if ($idServicio != false){
			       $data['IdServicio'] = $idServicio;
			   }
			    
			   $data['clasificacion_servicios'] = $clasificacion;	
			   $datos = $this->mcompania->updateRegistro($data,$idInbound);
			}
		
	  }
	
	  public function loadArraySearch($var)
	  {
	      $this->db->like('Contacto',$var);
	      
	      $result = $this->db->get_where($this->_nameTable);
	  	  return $this->getModeloArrayFromQueryResult($result);
	  } 
	 
	  public function getModeloArrayFromQueryResult($result)
	  {
		
	   	if ($result->num_rows() == 0)
			return false;
		
	       $modeloUbicacionArr = array(); 
	         foreach ($result->result() as $record) 
		      {
			    $modeloUbicacionArr[] = new M_ContactoEntrega($record);
		      }
		
		return $modeloUbicacionArr;
       }
       
      public function loadConctatoId($id_ubicacion)
	  {
	  	$qresult = $this->db->get_where($this->_nameTable, array('Id_Referencia' => $id_ubicacion));

			if ($qresult->num_rows() == 0)
				return false;
	
			return new M_ContactoEntrega($qresult->row());
	  }
	  
	
	  public function crearNuevoContacto($data)
	  {
	  	  if ($this->db->insert($this->_nameTable, $data)){
	  	  	  return true;
	  	  }
		      return false;
	  }
	  
	  public function updateContacto($data,$where)
	  {
	      if ($this->db->update($this->_nameTable,$data,$where)) {
	      	  return true;
	      }	
	      
	       return false;
	  	
	  }
	  
    
}

class M_ContactoEntrega{
	
	  private $_Contacto;
	  private $_IdReferencia;
	  private $_Telefono1;
	  private $_Telefono2;
	  private $_EmailCia;
	  
	  public function __construct($objeto)
	  {
	  	 
	  	  $this->setIdReferencia($objeto->Id_Referencia);
	  	  $this->setTelefono1($objeto->Telefono1);
	  	  $this->setTelefono2($objeto->Telefono2);
	  	  $this->setEmailCia($objeto->Email_Cia);
	  	  $this->setContacto($objeto->Contacto);
	  }
      
      public function getIdReferencia()
      {
      	 return $this->_IdReferencia;
      }

      public function setIdReferencia($value)
      {
      	 $this->_IdReferencia = $value; 
      }
      
      public function getTelefono1()
      {
      	 return $this->_Telefono1;
      }

      public function setTelefono1($value)
      {
      	 $this->_Telefono1 = $value; 
      }
      
      public function getTelefono2()
      {
      	 return $this->_Telefono2;
      }

      public function setTelefono2($value)
      {
      	 $this->_Telefono2 = $value; 
      }
      
      public function getEmailCia()
      {
      	 return $this->_EmailCia;
      }

      public function setEmailCia($value)
      {
      	 $this->_EmailCia = $value; 
      }
      
      public function setContacto($value)
      {
      	 $this->_Contacto = $value;
      }
      
      public function getContacto()
      {
      	 return $this->_Contacto;
      }
	
}
?>